

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/fluid.png">
  <link rel="icon" href="/img/fluid.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="John Doe">
  <meta name="keywords" content="">
  
    <meta name="description" content="若发现文章有误或有任何建议，敬请指教，感谢@[TOC]  一、Hadoop-HA 概述 HA，即High Availablity，高可用，指的是集群能7 * 24 小时不中断服务。实现高可用最关键的策略是消除单点故障。HA严格来说应该分成各个组件的HA机制：HDFS的HA和YARN的HA。 NameNode主要在以下两个方面影响HDFS集群：  NameNode机器发生以外，如宕机，集群将无法">
<meta property="og:type" content="article">
<meta property="og:title" content="Hadoop HA高可用 学习笔记（一） HDFS-HA 手动、自动模式 _ YARN-HA 自动模式 _ 模拟宕机故障 _ HA-基于Zookeeper">
<meta property="og:url" content="http://example.com/2022/04/06/Hadoop%20HA%E9%AB%98%E5%8F%AF%E7%94%A8%20%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0%EF%BC%88%E4%B8%80%EF%BC%89%20HDFS-HA%20%E6%89%8B%E5%8A%A8%E3%80%81%E8%87%AA%E5%8A%A8%E6%A8%A1%E5%BC%8F%20_%20YARN-HA%20%E8%87%AA%E5%8A%A8%E6%A8%A1%E5%BC%8F%20_%20%E6%A8%A1%E6%8B%9F%E5%AE%95%E6%9C%BA%E6%95%85%E9%9A%9C%20_%20HA-%E5%9F%BA%E4%BA%8EZookeeper/index.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="若发现文章有误或有任何建议，敬请指教，感谢@[TOC]  一、Hadoop-HA 概述 HA，即High Availablity，高可用，指的是集群能7 * 24 小时不中断服务。实现高可用最关键的策略是消除单点故障。HA严格来说应该分成各个组件的HA机制：HDFS的HA和YARN的HA。 NameNode主要在以下两个方面影响HDFS集群：  NameNode机器发生以外，如宕机，集群将无法">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://img-blog.csdnimg.cn/2c3ee0f958c4477c8596b31d83906b70.png#pic_center">
<meta property="og:image" content="https://img-blog.csdnimg.cn/cc15f2cec8f5408facbc060c72148e0f.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/60e803233bf548789dc5cdd4e27342d3.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/f10c39a61ce8436998ca0879f8122c6b.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/d40866cd78114b7f9302ef61a0fce853.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/5d29f3e8aae344a9b4fe60e43d901ab9.png">
<meta property="article:published_time" content="2022-04-06T11:27:15.000Z">
<meta property="article:modified_time" content="2022-08-22T15:44:30.337Z">
<meta property="article:author" content="John Doe">
<meta property="article:tag" content="Hadoop">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="https://img-blog.csdnimg.cn/2c3ee0f958c4477c8596b31d83906b70.png#pic_center">
  
  
  
  <title>Hadoop HA高可用 学习笔记（一） HDFS-HA 手动、自动模式 _ YARN-HA 自动模式 _ 模拟宕机故障 _ HA-基于Zookeeper - Hexo</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/css/highlight-dark.css" />
  




  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"example.com","root":"/","version":"1.9.2","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"follow_dnt":true,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml"};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
  


  
<meta name="generator" content="Hexo 6.2.0"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 70vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>尤 Ni&#39;s Blog</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              &nbsp;<i class="iconfont icon-search"></i>&nbsp;
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/img/default.png') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="Hadoop HA高可用 学习笔记（一） HDFS-HA 手动、自动模式 _ YARN-HA 自动模式 _ 模拟宕机故障 _ HA-基于Zookeeper"></span>
          
        </div>

        
          
  <div class="mt-3">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-author" aria-hidden="true"></i>
        John Doe
      </span>
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2022-04-06 19:27" pubdate>
          2022年4月6日 晚上
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          22k 字
        
      </span>
    

    
      <span class="post-meta mr-2">
        <i class="iconfont icon-clock-fill"></i>
        
        
        
          182 分钟
        
      </span>
    

    
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      

    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">Hadoop HA高可用 学习笔记（一） HDFS-HA 手动、自动模式 _ YARN-HA 自动模式 _ 模拟宕机故障 _ HA-基于Zookeeper</h1>
            
              <p class="note note-info">
                
                  
                    本文最后更新于：1 小时前
                  
                
              </p>
            
            
              <div class="markdown-body">
                
                <p><img src="https://img-blog.csdnimg.cn/2c3ee0f958c4477c8596b31d83906b70.png#pic_center" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<blockquote>
<p>若发现文章有误或有任何建议，敬请指教，感谢<br>@[TOC]</p>
</blockquote>
<h1 id="一、Hadoop-HA-概述"><a href="#一、Hadoop-HA-概述" class="headerlink" title="一、Hadoop-HA 概述"></a>一、Hadoop-HA 概述</h1><hr>
<p>HA，即High Availablity，高可用，指的是集群能7 * 24 小时不中断服务。<br>实现高可用最关键的策略是消除单点故障。HA严格来说应该分成各个组件的HA机制：HDFS的HA和YARN的HA。</p>
<p>NameNode主要在以下两个方面影响HDFS集群：</p>
<ol>
<li>NameNode机器发生以外，如宕机，集群将无法使用，直到管理员重启</li>
<li>NameNode机器需要升级，包括软件、硬件升级，此时集群也将无法使用</li>
</ol>
<p>HDFS HA 功能通过配置多个NameNodes(Activity &#x2F; Standby）实现在集群中对NameNode的热备来解决上述问题。</p>
<p>如果出现故障，如机器崩溃或机器需要升级维护，这时可通过该方法将NameNode很快的切换到另一台机器。</p>
<h2 id="1-1-HDFS-HA-集群搭建"><a href="#1-1-HDFS-HA-集群搭建" class="headerlink" title="1.1 HDFS-HA 集群搭建"></a>1.1 HDFS-HA 集群搭建</h2><p>原始HDFS集群的规划：</p>
<table>
<thead>
<tr>
<th>节点1</th>
<th>节点2</th>
<th>节点3</th>
</tr>
</thead>
<tbody><tr>
<td>NameNode</td>
<td>\</td>
<td>SecondaryNameNode</td>
</tr>
<tr>
<td>DataNode</td>
<td>DataNode</td>
<td>DataNode</td>
</tr>
</tbody></table>
<p>HA的主要目的是消除NameNode的单点故障，HDFS-HA的节点分配：</p>
<table>
<thead>
<tr>
<th>节点1</th>
<th>节点2</th>
<th>节点3</th>
</tr>
</thead>
<tbody><tr>
<td>NameNode</td>
<td>NameNode</td>
<td>NameNode</td>
</tr>
<tr>
<td>DataNode</td>
<td>DataNode</td>
<td>DataNode</td>
</tr>
</tbody></table>
<h2 id="1-2-HDFS-HA-核心问题"><a href="#1-2-HDFS-HA-核心问题" class="headerlink" title="1.2 HDFS-HA 核心问题"></a>1.2 HDFS-HA 核心问题</h2><p><strong>1）如何保证三台NameNode的数据一致？</strong><br>a. FsImage：让一台NN生成数据，让其他机器NN同步<br>b. Edits：需要引进新的模块 JournalNode 来保证 edits文件的数据一致性<br><strong>2）怎么让同时只有一台NN是active，其他的NN为standby模式？</strong><br>a.手动分配<br>b.自动分配<br><strong>3) 2NN 在 HA架构中并不存在，谁来定期合并 fsImage 和 edits？</strong><br>由standby的NN处理<br><strong>4）若当前NN出现了故障，怎么切换到其他的NN？</strong>(Zookeeper）<br>a.手动故障转移<br>b.自动故障转移</p>
<h1 id="二、HDFS-HA-手动模式"><a href="#二、HDFS-HA-手动模式" class="headerlink" title="二、HDFS-HA 手动模式"></a>二、HDFS-HA 手动模式</h1><hr>
<table>
<thead>
<tr>
<th>节点1</th>
<th>节点2</th>
<th>节点3</th>
</tr>
</thead>
<tbody><tr>
<td>NameNode</td>
<td>NameNode</td>
<td>NameNode</td>
</tr>
<tr>
<td>JournalNode</td>
<td>JournalNode</td>
<td>JournalNode</td>
</tr>
<tr>
<td>DataNode</td>
<td>DataNode</td>
<td>DataNode</td>
</tr>
</tbody></table>
<p>笔者是通过之前的Hadoop集群迁移过来的，这里将原先的hadoop文件夹拷贝一份，删除里面的日志logs，和NN、DN的信息，然后分发给其他两个节点。</p>
<p>若是第一次安装hadoop，则可通过清华大学镜像站下载：<a target="_blank" rel="noopener" href="https://mirrors.tuna.tsinghua.edu.cn/apache/hadoop/common/hadoop-3.3.1/hadoop-3.3.1.tar.gz">hadoop3.3.1.tar.gz</a></p>
<h2 id="2-1-配置Hadoop"><a href="#2-1-配置Hadoop" class="headerlink" title="2.1  配置Hadoop"></a>2.1  配置Hadoop</h2><p>提示：配置文件都在hadoop根目录下的&#x2F;etc&#x2F;hadoop里</p>
<p><strong>注：由于笔者是用Docker容器的root用户测试的，在运行时，显示未指定用户，所以这里笔者先在hadoop-env.sh里添加了一些报错提示的用户。同时指定JDK</strong><br><code>hadoop-env.sh</code></p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><code class="hljs xml">export JAVA_HOME=/opt/java/jdk8<br>export HDFS_NAMENODE_USER=root<br>export HDFS_DATANODE_USER=root<br>export HDFS_SECONDARYNAMENODE_USER=root<br>export YARN_RESOURCEMANAGER_USER=root<br>export YARN_NODEMANAGER_USER=root<br>export HDFS_JOURNALNODE_USER=root<br>export HDFS_ZKFC_USER=root<br></code></pre></td></tr></table></figure>

<p><strong>1.core-site.xml</strong></p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><code class="hljs xml"><span class="hljs-meta">&lt;?xml version=<span class="hljs-string">&quot;1.0&quot;</span>?&gt;</span><br><span class="hljs-meta">&lt;?xml-stylesheet type=<span class="hljs-string">&quot;text/xsl&quot;</span> href=<span class="hljs-string">&quot;configuration.xsl&quot;</span>?&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">configuration</span>&gt;</span><br>	<span class="hljs-comment">&lt;!-- 把多个NameNode的地址组装成一个集群cluster --&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">property</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>fs.defaultFS<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>hdfs://cluster<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span><br>    <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span><br>    <span class="hljs-comment">&lt;!-- 指定hadoop运行时产生的存储目录 --&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">property</span>&gt;</span><br>    	 <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>hadoop.tmp.dir<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span><br>    	 <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>/opt/module/hadoopha/data<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span><br>    <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">configuration</span>&gt;</span><br></code></pre></td></tr></table></figure>

<p><strong>2.hdfs-site.xml</strong></p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br></pre></td><td class="code"><pre><code class="hljs xml"><span class="hljs-meta">&lt;?xml version=<span class="hljs-string">&quot;1.0&quot;</span>?&gt;</span><br><span class="hljs-meta">&lt;?xml-stylesheet type=<span class="hljs-string">&quot;text/xsl&quot;</span> href=<span class="hljs-string">&quot;configuration.xsl&quot;</span>?&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">configuration</span>&gt;</span><br>   <span class="hljs-comment">&lt;!--1. NameNode数据存储目录 --&gt;</span><br>   <span class="hljs-tag">&lt;<span class="hljs-name">property</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>dfs.namenode.name.dir<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>file://$&#123;hadoop.tmp.dir&#125;/name<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span><br>   <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span><br>   <span class="hljs-comment">&lt;!--2. DataNode数据存储目录 --&gt;</span><br>   <span class="hljs-tag">&lt;<span class="hljs-name">property</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>dfs.datanode.data.dir<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>file://$&#123;hadoop.tmp.dir&#125;/data<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span><br>   <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span><br>   <span class="hljs-comment">&lt;!--3. JournalNode数据存储目录 --&gt;</span><br>   <span class="hljs-tag">&lt;<span class="hljs-name">property</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>dfs.journalnode.edits.dir<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>$&#123;hadoop.tmp.dir&#125;/jn<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span><br>   <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span><br>   <span class="hljs-comment">&lt;!--4. 完全分布式集群名称 --&gt;</span><br>   <span class="hljs-tag">&lt;<span class="hljs-name">property</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>dfs.nameservices<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>cluster<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span><br>   <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span><br>   <span class="hljs-comment">&lt;!--5. 指定集群中的NameNode节点 --&gt;</span><br>   <span class="hljs-tag">&lt;<span class="hljs-name">property</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>dfs.ha.namenodes.cluster<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>nn1,nn2,nn3<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span><br>   <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span><br>   <span class="hljs-comment">&lt;!--6. 每个NameNode节点的RPC通信地址 --&gt;</span><br>   <span class="hljs-tag">&lt;<span class="hljs-name">property</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>dfs.namenode.rpc-address.cluster.nn1<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>hadoop101:8020<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span><br>   <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span><br>   <span class="hljs-tag">&lt;<span class="hljs-name">property</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>dfs.namenode.rpc-address.cluster.nn2<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>hadoop102:8020<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span><br>   <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span><br>   <span class="hljs-tag">&lt;<span class="hljs-name">property</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>dfs.namenode.rpc-address.cluster.nn3<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>hadoop103:8020<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span><br>   <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span><br>   <span class="hljs-comment">&lt;!--7. 每个NameNode节点的HTTP Web访问地址 --&gt;</span><br>   <span class="hljs-tag">&lt;<span class="hljs-name">property</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>dfs.namenode.http-address.cluster.nn1<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>hadoop101:9870<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span><br>   <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">property</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>dfs.namenode.http-address.cluster.nn2<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>hadoop102:9870<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span><br>   <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">property</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>dfs.namenode.http-address.cluster.nn3<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>hadoop103:9870<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span><br>   <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span><br>   <span class="hljs-comment">&lt;!--8. 指定NameNode 元数据在JournalNode上的存储位置--&gt;</span><br>   <span class="hljs-tag">&lt;<span class="hljs-name">property</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>dfs.namenode.shared.edits.dir<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>qjournal://hadoop101:8485;hadoop102:8485;hadoop103:8485/cluster<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span><br>   <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span><br><br>   <span class="hljs-comment">&lt;!--9. 访问代理类: client用于确定哪个NameNode为Active状态--&gt;</span><br>   <span class="hljs-tag">&lt;<span class="hljs-name">property</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>dfs.client.failover.proxy.provider.cluster<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span><br>   <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span><br>   <span class="hljs-comment">&lt;!--10. 设置隔离机制，即同一时刻只能有一台服务器对外响应 --&gt;</span><br>   <span class="hljs-tag">&lt;<span class="hljs-name">property</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>dfs.ha.fencing.methods<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>sshfence<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span><br>   <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span><br>   <span class="hljs-comment">&lt;!--11. 使用隔离机制时需要ssh密钥登录 --&gt;</span><br>   <span class="hljs-tag">&lt;<span class="hljs-name">property</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>dfs.ha.fencing.ssh.private-key-files<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>/root/.ssh/id_rsa<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span><br>   <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">configuration</span>&gt;</span>    <br></code></pre></td></tr></table></figure>
<p>其他配置文件mapred-site.xml、yarn-site.xml暂时采用默认。注：workers文件需填写所有的集群节点，例：</p>
<figure class="highlight smali"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs smali">hadoop101<br>hadoop102<br>hadoop103<br></code></pre></td></tr></table></figure>

<p>配置好后分发到其他集群节点：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs shell"><span class="hljs-meta prompt_">$ </span><span class="language-bash">scp -r /opt/module/hadoopha/etc/hadoop root@hadoop102:/opt/module/hadoopha/etc</span><br><span class="hljs-meta prompt_">$ </span><span class="language-bash">scp -r /opt/module/hadoopha/etc/hadoop root@hadoop103:/opt/module/hadoopha/etc</span><br></code></pre></td></tr></table></figure>

<p>配置Hadoop环境变量</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell"><span class="hljs-meta prompt_">$ </span><span class="language-bash">vim /etc/profile.d/home.sh</span><br></code></pre></td></tr></table></figure>

<p>配置内容：</p>
<figure class="highlight routeros"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs routeros"><span class="hljs-built_in">export</span> <span class="hljs-attribute">HADOOP_HOME</span>=/opt/module/hadoopha<br><span class="hljs-built_in">export</span> <span class="hljs-attribute">PATH</span>=<span class="hljs-variable">$PATH</span>:$HADOOP_HOME/bin:$HADOOP_HOME/sbin<br></code></pre></td></tr></table></figure>
<p>使环境变量生效</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell"><span class="hljs-meta prompt_">$ </span><span class="language-bash"><span class="hljs-built_in">source</span> /etc/profile</span><br></code></pre></td></tr></table></figure>
<p>其他的两个节点也需要配置<code>HADOOP_HOME</code>，步骤一样</p>
<h2 id="2-2-启动集群"><a href="#2-2-启动集群" class="headerlink" title="2.2 启动集群"></a>2.2 启动集群</h2><p><strong>第一步，启动每个集群节点的journalnode（在hadoop101执行命令即可）</strong></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs shell"><span class="hljs-meta prompt_">$ </span><span class="language-bash">hdfs --daemon start journalnode</span><br><span class="hljs-meta prompt_">$ </span><span class="language-bash">ssh root@hadoop102 hdfs --daemon start journalnode</span><br><span class="hljs-meta prompt_">$ </span><span class="language-bash">ssh root@hadoop103 hdfs --daemon start journalnode</span><br></code></pre></td></tr></table></figure>
<p>查看集群节点的Java进程</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs shell"><span class="hljs-meta prompt_">$ </span><span class="language-bash"><span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> hadoop101 hadoop102 hadoop103;</span><br>do echo ====节点$i====;<br>ssh $i jps;<br>done<br></code></pre></td></tr></table></figure>
<p>运行结果：</p>
<figure class="highlight abnf"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><code class="hljs abnf"><span class="hljs-operator">=</span><span class="hljs-operator">=</span><span class="hljs-operator">=</span><span class="hljs-operator">=</span>节点hadoop101<span class="hljs-operator">=</span><span class="hljs-operator">=</span><span class="hljs-operator">=</span><span class="hljs-operator">=</span><br><span class="hljs-number">996</span> Jps<br><span class="hljs-number">764</span> JournalNode<br><span class="hljs-operator">=</span><span class="hljs-operator">=</span><span class="hljs-operator">=</span><span class="hljs-operator">=</span>节点hadoop102<span class="hljs-operator">=</span><span class="hljs-operator">=</span><span class="hljs-operator">=</span><span class="hljs-operator">=</span><br><span class="hljs-number">499</span> JournalNode<br><span class="hljs-number">653</span> Jps<br><span class="hljs-operator">=</span><span class="hljs-operator">=</span><span class="hljs-operator">=</span><span class="hljs-operator">=</span>节点hadoop103<span class="hljs-operator">=</span><span class="hljs-operator">=</span><span class="hljs-operator">=</span><span class="hljs-operator">=</span><br><span class="hljs-number">385</span> JournalNode<br><span class="hljs-number">539</span> Jps<br></code></pre></td></tr></table></figure>
<p><strong>第二步，在nn1上格式化NameNode，并启动，其他节点nn2和nn3去同步nn1的元数据信息</strong></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs shell">[root@hadoop101 hadoop]# hdfs namenode -format<br>[root@hadoop101 hadoop]# hdfs --daemon start namenode<br></code></pre></td></tr></table></figure>
<p>在nn2和nn3上同步nn1的元数据</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs shell">[root@hadoop102 hadoop]# hdfs namenode -bootstrapStandby<br>[root@hadoop103 hadoop]# hdfs namenode -bootstrapStandby<br></code></pre></td></tr></table></figure>
<p>启动nn2和nn3</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs shell">[root@hadoop102 hadoop]# hdfs --daemon start namenode<br>[root@hadoop103 hadoop]# hdfs --daemon start namenode<br></code></pre></td></tr></table></figure>
<p>启动集群节点的DataNode：</p>
<figure class="highlight autoit"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs autoit">```shell<br>[root<span class="hljs-symbol">@hadoop101</span> hadoopha]<span class="hljs-meta"># hdfs --daemon start datanode</span><br>[root<span class="hljs-symbol">@hadoop102</span> hadoopha]<span class="hljs-meta"># hdfs --daemon start datanode</span><br>[root<span class="hljs-symbol">@hadoop103</span> hadoopha]<span class="hljs-meta"># hdfs --daemon start datanode</span><br></code></pre></td></tr></table></figure>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs bash">查看集群节点Java进程：<br>```shell<br>$ <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> hadoop101 hadoop102 hadoop103;<br><span class="hljs-keyword">do</span> <span class="hljs-built_in">echo</span> ====节点<span class="hljs-variable">$i</span>====;<br>ssh <span class="hljs-variable">$i</span> jps;<br><span class="hljs-keyword">done</span><br></code></pre></td></tr></table></figure>
<p>运行结果：</p>
<figure class="highlight abnf"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><code class="hljs abnf"><span class="hljs-operator">=</span><span class="hljs-operator">=</span><span class="hljs-operator">=</span><span class="hljs-operator">=</span>节点hadoop101<span class="hljs-operator">=</span><span class="hljs-operator">=</span><span class="hljs-operator">=</span><span class="hljs-operator">=</span><br><span class="hljs-number">2864</span> JournalNode<br><span class="hljs-number">3379</span> DataNode<br><span class="hljs-number">3515</span> Jps<br><span class="hljs-number">3071</span> NameNode<br><span class="hljs-operator">=</span><span class="hljs-operator">=</span><span class="hljs-operator">=</span><span class="hljs-operator">=</span>节点hadoop102<span class="hljs-operator">=</span><span class="hljs-operator">=</span><span class="hljs-operator">=</span><span class="hljs-operator">=</span><br><span class="hljs-number">2115</span> Jps<br><span class="hljs-number">1594</span> JournalNode<br><span class="hljs-number">1997</span> DataNode<br><span class="hljs-number">1774</span> NameNode<br><span class="hljs-operator">=</span><span class="hljs-operator">=</span><span class="hljs-operator">=</span><span class="hljs-operator">=</span>节点hadoop103<span class="hljs-operator">=</span><span class="hljs-operator">=</span><span class="hljs-operator">=</span><span class="hljs-operator">=</span><br><span class="hljs-number">1680</span> Jps<br><span class="hljs-number">1153</span> JournalNode<br><span class="hljs-number">1333</span> NameNode<br><span class="hljs-number">1562</span> DataNode<br></code></pre></td></tr></table></figure>
<p>除此之外，我们可通过Web页面来访问NameNode，如：<a target="_blank" rel="noopener" href="http://hadoop101:9870/">http://hadoop101:9870</a><br><img src="https://img-blog.csdnimg.cn/cc15f2cec8f5408facbc060c72148e0f.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<h2 id="2-3-手动切换NameNode状态为Active"><a href="#2-3-手动切换NameNode状态为Active" class="headerlink" title="2.3  手动切换NameNode状态为Active"></a>2.3  手动切换NameNode状态为Active</h2><p>例如：将Hadoop101节点的NameNode从StandBy状态切换为Active状态</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs shell">[root@hadoop101 hadoopha]# hdfs haadmin -transitionToActive nn1<br><span class="hljs-meta prompt_">#</span><span class="language-bash">查看NameNode节点的状态</span><br>[root@hadoop101 hadoopha]# hdfs haadmin -getServiceState nn1<br></code></pre></td></tr></table></figure>
<p>运行结果：</p>
<figure class="highlight ebnf"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs ebnf"><span class="hljs-attribute">active</span><br></code></pre></td></tr></table></figure>
<p>通过Web页面查看：<br><img src="https://img-blog.csdnimg.cn/60e803233bf548789dc5cdd4e27342d3.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<h2 id="2-4-模拟宕机故障——手动关闭active的NameNode"><a href="#2-4-模拟宕机故障——手动关闭active的NameNode" class="headerlink" title="2.4 模拟宕机故障——手动关闭active的NameNode"></a>2.4 模拟宕机故障——手动关闭active的NameNode</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell">[root@hadoop101 hadoopha]# jps | grep NameNode | awk &#x27;&#123;print $1&#125;&#x27; | xargs kill -9<br></code></pre></td></tr></table></figure>

<p>经测试，关闭nn1后，nn2和nn3仍然是standby模式，此时尝试手动将nn2切换成active：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell">[root@hadoop102 hadoopha]# hdfs haadmin -transitionToActive nn2<br></code></pre></td></tr></table></figure>
<p>出现报错：</p>
<figure class="highlight pgsql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs pgsql">Unexpected error occurred  <span class="hljs-keyword">Call</span> <span class="hljs-keyword">From</span> hadoop102/<span class="hljs-number">172.17</span><span class="hljs-number">.0</span><span class="hljs-number">.3</span> <span class="hljs-keyword">to</span> hadoop101:<span class="hljs-number">8020</span> failed <span class="hljs-keyword">on</span> <span class="hljs-keyword">connection</span> <span class="hljs-keyword">exception</span>: java.net.ConnectException: <span class="hljs-keyword">Connection</span> refused;<br></code></pre></td></tr></table></figure>
<p>由于nn1宕机了，所以无法手动的将nn2切换至active状态，此时再次开启nn1</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs shell">[root@hadoop101 hadoopha]# hdfs --daemon start namenode<br><span class="hljs-meta prompt_">#</span><span class="language-bash">查看nn1节点的状态</span><br>[root@hadoop101 hadoopha]# hdfs haadmin -getServiceState nn1<br></code></pre></td></tr></table></figure>
<p>经重启后，nn1回到了standby状态，此时再次将nn2切换为active模式</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs shell">[root@hadoop102 hadoopha]# hdfs haadmin -transitionToActive nn2<br><span class="hljs-meta prompt_">#</span><span class="language-bash">查看nn2节点的状态</span><br>[root@hadoop101 hadoopha]# hdfs haadmin -getServiceState nn2<br></code></pre></td></tr></table></figure>
<p>运行结果：</p>
<figure class="highlight ebnf"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs ebnf"><span class="hljs-attribute">active</span><br></code></pre></td></tr></table></figure>
<p>此时在nn1切换状态：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell">[root@hadoop101 hadoopha]# hdfs haadmin -transitionToActive nn1<br></code></pre></td></tr></table></figure>
<p>运行结果（失败）：</p>
<figure class="highlight crmsh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs crmsh">transitionToActive: <span class="hljs-keyword">Node</span> <span class="hljs-title">nn2</span> is already active<br></code></pre></td></tr></table></figure>
<p>当nn1重新上线时，nn2才能切换到active状态，而且在HA中只允许单个namenode为active状态</p>
<p>综上，手动模式下，需要所有的NameNode都处于正常运行状态时，才能设置某个nn为active状态。（有些鸡肋）</p>
<h1 id="三、HDFS-HA-自动模式"><a href="#三、HDFS-HA-自动模式" class="headerlink" title="三、HDFS-HA 自动模式"></a>三、HDFS-HA 自动模式</h1><hr>
<h2 id="3-1-HDFS-HA-自动故障转移工作机制"><a href="#3-1-HDFS-HA-自动故障转移工作机制" class="headerlink" title="3.1  HDFS-HA 自动故障转移工作机制"></a>3.1  HDFS-HA 自动故障转移工作机制</h2><p>自动故障转移为HDFS部署增加了两个新组件：Zookeeper和ZKFailoverController（ZKFC）进程，如下图，Zookeeper是维护少量协调数据，通知客户端这些数据的改变和监视客户端故障的高可用服务。</p>
<p><img src="https://img-blog.csdnimg.cn/f10c39a61ce8436998ca0879f8122c6b.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<h2 id="3-2-HDFS-HA-集群规划"><a href="#3-2-HDFS-HA-集群规划" class="headerlink" title="3.2  HDFS-HA 集群规划"></a>3.2  HDFS-HA 集群规划</h2><p>注：配置前记得关闭之前测试的NameNode、DataNode和JournalNode</p>
<table>
<thead>
<tr>
<th>节点1</th>
<th>节点2</th>
<th>节点3</th>
</tr>
</thead>
<tbody><tr>
<td>NameNode</td>
<td>NameNode</td>
<td>NameNode</td>
</tr>
<tr>
<td>JournalNode</td>
<td>JournalNode</td>
<td>JournalNode</td>
</tr>
<tr>
<td>DataNode</td>
<td>DataNode</td>
<td>DataNode</td>
</tr>
<tr>
<td>Zookeeper</td>
<td>Zookeeper</td>
<td>Zookeeper</td>
</tr>
<tr>
<td>ZKFC</td>
<td>ZKFC</td>
<td>ZKFC</td>
</tr>
</tbody></table>
<h2 id="3-3-配置-HDFS-HA-自动故障转移"><a href="#3-3-配置-HDFS-HA-自动故障转移" class="headerlink" title="3.3  配置 HDFS-HA 自动故障转移"></a>3.3  配置 HDFS-HA 自动故障转移</h2><p>这里主要配置core-site.xml和hdfs-site.xml这两个配置文件，其他的配置暂时默认</p>
<p>相比于手动的配置，配置内容的区别分别在于：<br><strong>1.core-site.xml 添加ZKFC要连接的zkServer地址</strong></p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs xml"><span class="hljs-comment">&lt;!-- 指定ZKFC要连接的zkServer地址 --&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">property</span>&gt;</span><br>     <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>ha.zookeeper.quorum<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span><br>     <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>hadoop101:2181,hadoop102:2181,hadoop103:2181<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span><br></code></pre></td></tr></table></figure>
<p>core-site.xml 完整的配置：</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><code class="hljs xml"><span class="hljs-meta">&lt;?xml version=<span class="hljs-string">&quot;1.0&quot;</span>?&gt;</span><br><span class="hljs-meta">&lt;?xml-stylesheet type=<span class="hljs-string">&quot;text/xsl&quot;</span> href=<span class="hljs-string">&quot;configuration.xsl&quot;</span>?&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">configuration</span>&gt;</span><br>   <span class="hljs-comment">&lt;!-- 把多个NameNode的地址组装成一个集群cluster --&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">property</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>fs.defaultFS<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>hdfs://cluster<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span><br>    <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span><br>    <span class="hljs-comment">&lt;!-- 指定hadoop运行时产生的存储目录 --&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">property</span>&gt;</span><br>         <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>hadoop.tmp.dir<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span><br>         <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>/opt/module/hadoopha/data<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span><br>    <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span><br>    <span class="hljs-comment">&lt;!-- 指定ZKFC要连接的zkServer地址 --&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">property</span>&gt;</span><br>         <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>ha.zookeeper.quorum<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span><br>         <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>hadoop101:2181,hadoop102:2181,hadoop103:2181<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span><br>    <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">configuration</span>&gt;</span><br></code></pre></td></tr></table></figure>
<p><strong>2.hdfs-site.xml 启动NN故障自动转移</strong></p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs xml"><span class="hljs-comment">&lt;!--12. 启动 NN 故障自动转移 --&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">property</span>&gt;</span><br>   <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>dfs.ha.automatic-failover.enabled<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span><br>   <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>true<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span><br></code></pre></td></tr></table></figure>
<p><code>hdfs-site.xml </code>完整的配置：</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br></pre></td><td class="code"><pre><code class="hljs xml"><span class="hljs-meta">&lt;?xml version=<span class="hljs-string">&quot;1.0&quot;</span>?&gt;</span><br><span class="hljs-meta">&lt;?xml-stylesheet type=<span class="hljs-string">&quot;text/xsl&quot;</span> href=<span class="hljs-string">&quot;configuration.xsl&quot;</span>?&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">configuration</span>&gt;</span><br>   <span class="hljs-comment">&lt;!--1. NameNode数据存储目录 --&gt;</span><br>   <span class="hljs-tag">&lt;<span class="hljs-name">property</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>dfs.namenode.name.dir<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>file://$&#123;hadoop.tmp.dir&#125;/name<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span><br>   <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span><br>   <span class="hljs-comment">&lt;!--2. DataNode数据存储目录 --&gt;</span><br>   <span class="hljs-tag">&lt;<span class="hljs-name">property</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>dfs.datanode.data.dir<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>file://$&#123;hadoop.tmp.dir&#125;/data<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span><br>   <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span><br>   <span class="hljs-comment">&lt;!--3. JournalNode数据存储目录 --&gt;</span><br>   <span class="hljs-tag">&lt;<span class="hljs-name">property</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>dfs.journalnode.edits.dir<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>$&#123;hadoop.tmp.dir&#125;/jn<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span><br>   <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span><br>   <span class="hljs-comment">&lt;!--4. 完全分布式集群名称 --&gt;</span><br>   <span class="hljs-tag">&lt;<span class="hljs-name">property</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>dfs.nameservices<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>cluster<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span><br>   <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span><br>   <span class="hljs-comment">&lt;!--5. 指定集群中的NameNode节点 --&gt;</span><br>   <span class="hljs-tag">&lt;<span class="hljs-name">property</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>dfs.ha.namenodes.cluster<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>nn1,nn2,nn3<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span><br>   <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span><br>   <span class="hljs-comment">&lt;!--6. 每个NameNode节点的RPC通信地址 --&gt;</span><br>   <span class="hljs-tag">&lt;<span class="hljs-name">property</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>dfs.namenode.rpc-address.cluster.nn1<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>hadoop101:8020<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span><br>   <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span><br>   <span class="hljs-tag">&lt;<span class="hljs-name">property</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>dfs.namenode.rpc-address.cluster.nn2<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>hadoop102:8020<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span><br>   <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span><br>   <span class="hljs-tag">&lt;<span class="hljs-name">property</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>dfs.namenode.rpc-address.cluster.nn3<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>hadoop103:8020<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span><br>   <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span><br>   <span class="hljs-comment">&lt;!--7. 每个NameNode节点的HTTP Web访问地址 --&gt;</span><br>   <span class="hljs-tag">&lt;<span class="hljs-name">property</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>dfs.namenode.http-address.cluster.nn1<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>hadoop101:9870<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span><br>   <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">property</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>dfs.namenode.http-address.cluster.nn2<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>hadoop102:9870<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span><br>   <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">property</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>dfs.namenode.http-address.cluster.nn3<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>hadoop103:9870<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span><br>   <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span><br>   <span class="hljs-comment">&lt;!--8. 指定NameNode 元数据在JournalNode上的存储位置--&gt;</span><br>   <span class="hljs-tag">&lt;<span class="hljs-name">property</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>dfs.namenode.shared.edits.dir<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>qjournal://hadoop101:8485;hadoop102:8485;hadoop103:8485/cluster<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span><br>   <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span><br><br>   <span class="hljs-comment">&lt;!--9. 访问代理类: client用于确定哪个NameNode为Active状态--&gt;</span><br>   <span class="hljs-tag">&lt;<span class="hljs-name">property</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>dfs.client.failover.proxy.provider.cluster<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span><br>   <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span><br>   <span class="hljs-comment">&lt;!--10. 设置隔离机制，即同一时刻只能有一台服务器对外响应 --&gt;</span><br>   <span class="hljs-tag">&lt;<span class="hljs-name">property</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>dfs.ha.fencing.methods<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>sshfence<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span><br>   <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span><br>   <span class="hljs-comment">&lt;!--11. 使用隔离机制时需要ssh密钥登录 --&gt;</span><br>   <span class="hljs-tag">&lt;<span class="hljs-name">property</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>dfs.ha.fencing.ssh.private-key-files<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>/root/.ssh/id_rsa<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span><br>   <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span><br>   <span class="hljs-comment">&lt;!--12. 启动 NN 故障自动转移 --&gt;</span><br>   <span class="hljs-tag">&lt;<span class="hljs-name">property</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>dfs.ha.automatic-failover.enabled<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>true<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span><br>   <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">configuration</span>&gt;</span><br></code></pre></td></tr></table></figure>

<p>配置好后分发配置文件到其他两个节点：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs shell"><span class="hljs-meta prompt_">$ </span><span class="language-bash">scp -r /opt/module/hadoopha/etc/hadoop root@hadoop102:/opt/module/hadoopha/etc</span><br><span class="hljs-meta prompt_">$ </span><span class="language-bash">scp -r /opt/module/hadoopha/etc/hadoop root@hadoop103:/opt/module/hadoopha/etc</span><br></code></pre></td></tr></table></figure>

<p>准备好配置文件后，接下来准备zk的安装与配置</p>
<h2 id="3-4-下载zokeeper并解压、配置"><a href="#3-4-下载zokeeper并解压、配置" class="headerlink" title="3.4  下载zokeeper并解压、配置"></a>3.4  下载zokeeper并解压、配置</h2><p>测试版本：zookeeper3.6.3</p>
<p>官方地址：<a target="_blank" rel="noopener" href="https://zookeeper.apache.org/releases.html">https://zookeeper.apache.org/releases.html</a></p>
<p>下载地址：<a target="_blank" rel="noopener" href="https://dlcdn.apache.org/zookeeper/zookeeper-3.6.3/apache-zookeeper-3.6.3-bin.tar.gz">https://dlcdn.apache.org/zookeeper/zookeeper-3.6.3/apache-zookeeper-3.6.3-bin.tar.gz</a></p>
<p>配置 zookeeper，这里现在一个节点上配置，配置好后分发，然后分发后需要改集群的ID</p>
<p>解压到本地后进入根目录下的conf文件夹</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs shell"><span class="hljs-meta prompt_">$ </span><span class="language-bash"><span class="hljs-built_in">cp</span> zoo_sample.cfg zoo.cfg</span><br><span class="hljs-meta prompt_"></span><br><span class="hljs-meta prompt_">$ </span><span class="language-bash">vim zoo.cfg</span><br></code></pre></td></tr></table></figure>
<p>拷贝一份官方的配置模板，然后进行配置，zoo.cfg的配置内容如下：<br>主要配置了zk的数据存储目录和其他zk集群节点的地址</p>
<figure class="highlight ini"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><code class="hljs ini"><span class="hljs-attr">tickTime</span>=<span class="hljs-number">2000</span><br><span class="hljs-attr">initLimit</span>=<span class="hljs-number">10</span><br><span class="hljs-attr">syncLimit</span>=<span class="hljs-number">5</span><br><span class="hljs-attr">dataDir</span>=/opt/module/zookeeper3.<span class="hljs-number">6.3</span>/dataDir<br><span class="hljs-attr">clientPort</span>=<span class="hljs-number">2181</span><br><br><span class="hljs-attr">server.1</span>=hadoop101:<span class="hljs-number">2888</span>:<span class="hljs-number">3888</span><br><span class="hljs-attr">server.2</span>=hadoop102:<span class="hljs-number">2888</span>:<span class="hljs-number">3888</span><br><span class="hljs-attr">server.3</span>=hadoop103:<span class="hljs-number">2888</span>:<span class="hljs-number">3888</span><br></code></pre></td></tr></table></figure>

<p>配置好zk后，配置zk的环境变量，之后进行分发</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell"><span class="hljs-meta prompt_">$ </span><span class="language-bash">vim /etc/profile.d/home.sh</span><br></code></pre></td></tr></table></figure>
<p>添加配置信息</p>
<figure class="highlight routeros"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs routeros"><span class="hljs-built_in">export</span> <span class="hljs-attribute">ZOOKEEPER_HOME</span>=/opt/module/zookeeper3.6.3<br><span class="hljs-built_in">export</span> <span class="hljs-attribute">PATH</span>=<span class="hljs-variable">$PATH</span>:$ZOOKEEPER_HOME/bin<br></code></pre></td></tr></table></figure>
<p>分发zk还有环境变量到hadoop102、hadoop103</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs shell"><span class="hljs-meta prompt_">$ </span><span class="language-bash">scp -r /opt/module/zookeeper3.6.3 root@hadoop102:/opt/module/</span><br><span class="hljs-meta prompt_">$ </span><span class="language-bash">scp -r /etc/profile.d/home.sh root@hadoop102:/etc/profile.d/</span><br><span class="hljs-meta prompt_"></span><br><span class="hljs-meta prompt_">$ </span><span class="language-bash">scp -r /opt/module/zookeeper3.6.3 root@hadoop103:/opt/module/</span><br><span class="hljs-meta prompt_">$ </span><span class="language-bash">scp -r /etc/profile.d/home.sh root@hadoop103:/etc/profile.d/</span><br></code></pre></td></tr></table></figure>
<p>使环境变量生效：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs shell">[root@hadoop101 ~]# source /etc/profile<br>[root@hadoop102 ~]# source /etc/profile<br>[root@hadoop103 ~]# source /etc/profile<br></code></pre></td></tr></table></figure>

<p>接下来在zookeeper根目录下的zkData目录下（没有则创建）创建一个myid的文件</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell">touch myid<br></code></pre></td></tr></table></figure>
<p>比如在hadoop101节点就在myid里添加一行内容，内容为1，在hadoop102节点就添加2，表示当前zk节点的编号，hadoop103添加为3。</p>
<h2 id="3-5-启动测试"><a href="#3-5-启动测试" class="headerlink" title="3.5 启动测试"></a>3.5 启动测试</h2><p><strong>1.启动zk集群</strong></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs shell">[root@hadoop101 ~]# zkServer.sh start<br>[root@hadoop102 ~]# zkServer.sh start<br>[root@hadoop103 ~]# zkServer.sh start<br></code></pre></td></tr></table></figure>
<p>启动后输入jps查看是否有zk的进程<code>QuorumPeerMain</code>，正常情况下，每个集群节点都会有该进程。</p>
<p><strong>2.在nn1节点初始化HA在zk中的状态</strong></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell">[root@hadoop101 ~]# hdfs zkfc -formatZK<br></code></pre></td></tr></table></figure>
<p><strong>3.启动 hdfs</strong><br> <figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell">[root@hadoop101 ~]# start-dfs.sh<br></code></pre></td></tr></table></figure></p>
<p><strong>4.查看节点的Java进程</strong></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs shell"><span class="hljs-meta prompt_">$ </span><span class="language-bash"><span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> hadoop101 hadoop102 hadoop103;</span><br>do echo ====节点$i====;<br>ssh $i jps;<br>done<br></code></pre></td></tr></table></figure>
<p>运行结果：</p>
<figure class="highlight abnf"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><code class="hljs abnf"><span class="hljs-operator">=</span><span class="hljs-operator">=</span><span class="hljs-operator">=</span><span class="hljs-operator">=</span>节点hadoop101<span class="hljs-operator">=</span><span class="hljs-operator">=</span><span class="hljs-operator">=</span><span class="hljs-operator">=</span><br><span class="hljs-number">5908</span> QuorumPeerMain<br><span class="hljs-number">8421</span> Jps<br><span class="hljs-number">7718</span> DataNode<br><span class="hljs-number">7547</span> NameNode<br><span class="hljs-number">8014</span> JournalNode<br><span class="hljs-number">8255</span> DFSZKFailoverController<br><span class="hljs-operator">=</span><span class="hljs-operator">=</span><span class="hljs-operator">=</span><span class="hljs-operator">=</span>节点hadoop102<span class="hljs-operator">=</span><span class="hljs-operator">=</span><span class="hljs-operator">=</span><span class="hljs-operator">=</span><br><span class="hljs-number">3493</span> NameNode<br><span class="hljs-number">3685</span> JournalNode<br><span class="hljs-number">3926</span> Jps<br><span class="hljs-number">3578</span> DataNode<br><span class="hljs-number">3786</span> DFSZKFailoverController<br><span class="hljs-number">2988</span> QuorumPeerMain<br><span class="hljs-operator">=</span><span class="hljs-operator">=</span><span class="hljs-operator">=</span><span class="hljs-operator">=</span>节点hadoop103<span class="hljs-operator">=</span><span class="hljs-operator">=</span><span class="hljs-operator">=</span><span class="hljs-operator">=</span><br><span class="hljs-number">2881</span> NameNode<br><span class="hljs-number">3073</span> JournalNode<br><span class="hljs-number">2386</span> QuorumPeerMain<br><span class="hljs-number">2966</span> DataNode<br><span class="hljs-number">3174</span> DFSZKFailoverController<br><span class="hljs-number">3303</span> Jps<br></code></pre></td></tr></table></figure>
<p><strong>5.进入zookeeper查看nn的数据</strong></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs shell"><span class="hljs-meta prompt_">$ </span><span class="language-bash">zkCli.sh</span><br><span class="hljs-meta prompt_"></span><br><span class="hljs-meta prompt_"># </span><span class="language-bash">注：命令里的cluster是之前在hadoop里core-site.xml文件里配置的fs.defaultFS参数值</span><br>[zk: localhost:2181(CONNECTED) 0] get -s /hadoop-ha/cluster/ActiveStandbyElectorLock<br></code></pre></td></tr></table></figure>
<p>运行结果：</p>
<figure class="highlight apache"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><code class="hljs apache"><span class="hljs-attribute">clusternn2</span>	hadoop102 �&gt;(�&gt;<br><span class="hljs-attribute">cZxid</span> = <span class="hljs-number">0</span>x2d00000007<br><span class="hljs-attribute">ctime</span> = Wed Apr <span class="hljs-number">06</span> <span class="hljs-number">14</span>:<span class="hljs-number">27</span>:<span class="hljs-number">06</span> UTC <span class="hljs-number">2022</span><br><span class="hljs-attribute">mZxid</span> = <span class="hljs-number">0</span>x2d00000007<br><span class="hljs-attribute">mtime</span> = Wed Apr <span class="hljs-number">06</span> <span class="hljs-number">14</span>:<span class="hljs-number">27</span>:<span class="hljs-number">06</span> UTC <span class="hljs-number">2022</span><br><span class="hljs-attribute">pZxid</span> = <span class="hljs-number">0</span>x2d00000007<br><span class="hljs-attribute">cversion</span> = <span class="hljs-number">0</span><br><span class="hljs-attribute">dataVersion</span> = <span class="hljs-number">0</span><br><span class="hljs-attribute">aclVersion</span> = <span class="hljs-number">0</span><br><span class="hljs-attribute">ephemeralOwner</span> = <span class="hljs-number">0</span>x20000a8aafa0001<br><span class="hljs-attribute">dataLength</span> = <span class="hljs-number">31</span><br><span class="hljs-attribute">numChildren</span> = <span class="hljs-number">0</span><br></code></pre></td></tr></table></figure>
<p>这里提示nn2是active节点，此时通过web（9870端口号）直接查看所有nn节点的状态，结果如下：<br><img src="https://img-blog.csdnimg.cn/d40866cd78114b7f9302ef61a0fce853.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"><br>通过结果发现，此时处于active状态的nn节点就和刚才在zk里查询到的节点一致，是hadoop102节点。</p>
<h2 id="3-6-故障测试"><a href="#3-6-故障测试" class="headerlink" title="3.6  故障测试"></a>3.6  故障测试</h2><p>根据之前的查询，hadoop102是处于active的nn2节点，此时将其namenode杀死，观察是否有其他节点变为active状态</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell">[root@hadoop102 ~]# jps | grep NameNode | awk &#x27;&#123;print $1&#125;&#x27; | xargs kill <br></code></pre></td></tr></table></figure>

<p>接下来再次从zk里查询当前的active的nn节点信息：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell">[zk: localhost:2181(CONNECTED) 1] get -s /hadoop-ha/cluster/ActiveStandbyElectorLock<br></code></pre></td></tr></table></figure>
<p>运行结果：</p>
<figure class="highlight apache"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><code class="hljs apache"><span class="hljs-attribute">clusternn1</span>	hadoop101 �&gt;(�&gt;<br><span class="hljs-attribute">cZxid</span> = <span class="hljs-number">0</span>x2d000000d5<br><span class="hljs-attribute">ctime</span> = Wed Apr <span class="hljs-number">06</span> <span class="hljs-number">14</span>:<span class="hljs-number">41</span>:<span class="hljs-number">09</span> UTC <span class="hljs-number">2022</span><br><span class="hljs-attribute">mZxid</span> = <span class="hljs-number">0</span>x2d000000d5<br><span class="hljs-attribute">mtime</span> = Wed Apr <span class="hljs-number">06</span> <span class="hljs-number">14</span>:<span class="hljs-number">41</span>:<span class="hljs-number">09</span> UTC <span class="hljs-number">2022</span><br><span class="hljs-attribute">pZxid</span> = <span class="hljs-number">0</span>x2d000000d5<br><span class="hljs-attribute">cversion</span> = <span class="hljs-number">0</span><br><span class="hljs-attribute">dataVersion</span> = <span class="hljs-number">0</span><br><span class="hljs-attribute">aclVersion</span> = <span class="hljs-number">0</span><br><span class="hljs-attribute">ephemeralOwner</span> = <span class="hljs-number">0</span>x20000a8aafa0015<br><span class="hljs-attribute">dataLength</span> = <span class="hljs-number">31</span><br><span class="hljs-attribute">numChildren</span> = <span class="hljs-number">0</span><br></code></pre></td></tr></table></figure>

<p>此时active的节点通过zk的选举制度变成了hadoop101，即nn1</p>
<p>接下来再将nn1关闭，查看最后的nn3是否能充当active的nn节点</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell">[root@hadoop101 ~]# jps | grep NameNode | awk &#x27;&#123;print $1&#125;&#x27; | xargs kill <br></code></pre></td></tr></table></figure>
<p>继续在zk里查看，</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell">[zk: localhost:2181(CONNECTED) 2] get -s /hadoop-ha/cluster/ActiveStandbyElectorLock<br></code></pre></td></tr></table></figure>

<p>最后返回的结果为，唯一存活的nn3节点，即hadoop103节点。</p>
<p>此时若再次启动之前估计关闭的两个nn节点，则active节点不会变化，刚启动的节点变成了standby模式。</p>
<h1 id="四、YARN-HA-自动模式"><a href="#四、YARN-HA-自动模式" class="headerlink" title="四、YARN-HA 自动模式"></a>四、YARN-HA 自动模式</h1><hr>
<p>官方参考文档：<a target="_blank" rel="noopener" href="https://hadoop.apache.org/docs/r3.3.0/hadoop-yarn/hadoop-yarn-site/ResourceManagerHA.html">点击查看</a>，工作机制：<br>![在这里插入图片描述](<a target="_blank" rel="noopener" href="https://img-blog.csdnimg.cn/f91a744e8c284af680ed6f9c80f93f90.png#">https://img-blog.csdnimg.cn/f91a744e8c284af680ed6f9c80f93f90.png#</a> &#x3D;80%x)<br>集群规划</p>
<table>
<thead>
<tr>
<th>节点1</th>
<th>节点2</th>
<th>节点3</th>
</tr>
</thead>
<tbody><tr>
<td>hadoop101</td>
<td>hadoop102</td>
<td>hadoop103</td>
</tr>
<tr>
<td>ResourceManager</td>
<td>ResourceManager</td>
<td>ResourceManager</td>
</tr>
<tr>
<td>NodeManager</td>
<td>NodeManager</td>
<td>NodeManager</td>
</tr>
<tr>
<td>Zookeeper</td>
<td>Zookeeper</td>
<td>Zookeeper</td>
</tr>
</tbody></table>
<p><strong>核心问题：</strong><br>1）若当前的Active RM 挂了，其他的RM如何将其他的standby RM 上位？</p>
<p><strong>答：</strong> 核心原理和HDFS-HA一样，利用了ZK的临时节点。</p>
<p>2）当前RM上有很多的计算程序都在等待运行，其他的RM怎么将这些程序接手过来接着运行？</p>
<p><strong>答：</strong> RM会将当前的所有计算程序的状态都存储在ZK中，其他RM上位后会去读取，然后接着运行</p>
<h2 id="4-1-配置YARN-HA"><a href="#4-1-配置YARN-HA" class="headerlink" title="4.1  配置YARN-HA"></a>4.1  配置YARN-HA</h2><p>配置文件在hadoop根目录下的&#x2F;etc&#x2F;hadoop&#x2F;yarn-site.xml</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br></pre></td><td class="code"><pre><code class="hljs xml"><span class="hljs-tag">&lt;<span class="hljs-name">configuration</span>&gt;</span><br>    <span class="hljs-comment">&lt;!--1. 配置 MR 走 shuffle --&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">property</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>yarn.nodemanager.aux-services<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>mapreduce_shuffle<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span><br>    <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span><br><br>    <span class="hljs-comment">&lt;!--2. 启用ResourceManager为HA模式--&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">property</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>yarn.resourcemanager.ha.enabled<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>true<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span><br>    <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span><br> <br>    <span class="hljs-comment">&lt;!--3. 声明ResourceManager集群节点ID--&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">property</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>yarn.resourcemanager.cluster-id<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>cluster-yarn<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span><br>    <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span><br>    <span class="hljs-comment">&lt;!--4. 声明ResourceManager集群的节点ID--&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">property</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>yarn.resourcemanager.ha.rm-ids<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>rm1,rm2,rm3<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span><br>    <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span><br>    <span class="hljs-comment">&lt;!-- =============== 5. rm1的配置 ============== --&gt;</span><br>         <span class="hljs-comment">&lt;!-- (1) 指定rm1主机名 --&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">property</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>yarn.resourcemanager.hostname.rm1<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>hadoop101<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span><br>    <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span><br>         <span class="hljs-comment">&lt;!-- (2) 指定rm1 web端访问地址--&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">property</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>yarn.resourcemanager.webapp.address.rm1<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>hadoop101:8088<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span><br>    <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span><br>         <span class="hljs-comment">&lt;!-- (3) 指定rm1内部通信地址--&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">property</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>yarn.resourcemanager.address.rm1<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>hadoop101:8032<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span><br>    <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span><br>         <span class="hljs-comment">&lt;!-- (4) 指定AM向rm1申请资源的地址--&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">property</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>yarn.resourcemanager.scheduler.address.rm1<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>hadoop101:8030<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span><br>    <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span><br>         <span class="hljs-comment">&lt;!-- (5) 指定NM连接的地址--&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">property</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>yarn.resourcemanager.resource-tracker.rm1<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>hadoop101:8031<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span><br>    <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span><br>    <span class="hljs-comment">&lt;!-- =============== 6. rm2的配置 ============== --&gt;</span><br>         <span class="hljs-comment">&lt;!-- (1) 指定rm2主机名 --&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">property</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>yarn.resourcemanager.hostname.rm2<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>hadoop102<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span><br>    <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span><br>         <span class="hljs-comment">&lt;!-- (2) 指定rm1 web端访问地址--&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">property</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>yarn.resourcemanager.webapp.address.rm2<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>hadoop102:8088<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span><br>    <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span><br>         <span class="hljs-comment">&lt;!-- (3) 指定rm2内部通信地址--&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">property</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>yarn.resourcemanager.address.rm2<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>hadoop102:8032<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span><br>    <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span><br>         <span class="hljs-comment">&lt;!-- (4) 指定AM向rm2申请资源的地址--&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">property</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>yarn.resourcemanager.scheduler.address.rm2<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>hadoop102:8030<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span><br>    <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span><br>         <span class="hljs-comment">&lt;!-- (5) 指定NM连接的地址--&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">property</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>yarn.resourcemanager.resource-tracker.rm2<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>hadoop102:8031<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span><br>    <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span><br>    <span class="hljs-comment">&lt;!-- =============== 7. rm3的配置 ============== --&gt;</span><br>         <span class="hljs-comment">&lt;!-- (1) 指定rm3主机名 --&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">property</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>yarn.resourcemanager.hostname.rm3<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>hadoop103<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span><br>    <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span><br>         <span class="hljs-comment">&lt;!-- (2) 指定rm3 web端访问地址--&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">property</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>yarn.resourcemanager.webapp.address.rm3<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>hadoop103:8088<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span><br>    <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span><br>         <span class="hljs-comment">&lt;!-- (3) 指定rm1内部通信地址--&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">property</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>yarn.resourcemanager.address.rm3<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>hadoop103:8032<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span><br>    <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span><br>         <span class="hljs-comment">&lt;!-- (4) 指定AM向rm1申请资源的地址--&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">property</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>yarn.resourcemanager.scheduler.address.rm3<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>hadoop103:8030<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span><br>    <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span><br>         <span class="hljs-comment">&lt;!-- (5) 指定NM连接的地址--&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">property</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>yarn.resourcemanager.resource-tracker.rm3<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>hadoop103:8031<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span><br>    <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span> <br>    <span class="hljs-comment">&lt;!--8. 指定zookeeper集群的地址--&gt;</span> <br>    <span class="hljs-tag">&lt;<span class="hljs-name">property</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>yarn.resourcemanager.zk-address<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>hadoop101:2181,hadoop102:2181,hadoop103:2181<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span><br>    <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span><br><br>    <span class="hljs-comment">&lt;!--9. 启用自动恢复--&gt;</span> <br>    <span class="hljs-tag">&lt;<span class="hljs-name">property</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>yarn.resourcemanager.recovery.enabled<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>true<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span><br>    <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span><br> <br>    <span class="hljs-comment">&lt;!--10. 指定resourcemanager的状态信息存储在zookeeper集群--&gt;</span> <br>    <span class="hljs-tag">&lt;<span class="hljs-name">property</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>yarn.resourcemanager.store.class<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>org.apache.hadoop.yarn.server.resourcemanager.recovery.ZKRMStateStore<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span><br>   <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span><br>   <span class="hljs-comment">&lt;!--11. 环境变量的继承 --&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">property</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>yarn.nodemanager.env-whitelist<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">value</span>&gt;</span>JAVA_HOME,HADOOP_COMMON_HOME,HADOOP_HDFS_HOME,HADOOP_CONF_DIR,CLASSPATH_PREPEND_DISTCACHE,HADOOP_YARN_HOME,HADOOP_MAPRED_HOME<span class="hljs-tag">&lt;/<span class="hljs-name">value</span>&gt;</span><br>   <span class="hljs-tag">&lt;/<span class="hljs-name">property</span>&gt;</span>   <br><span class="hljs-tag">&lt;/<span class="hljs-name">configuration</span>&gt;</span><br></code></pre></td></tr></table></figure>

<p>配置好后，分发到其他集群节点：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs shell"><span class="hljs-meta prompt_">$ </span><span class="language-bash">scp -r /opt/module/hadoopha/etc/hadoop root@hadoop102:/opt/module/hadoopha/etc</span><br><span class="hljs-meta prompt_">$ </span><span class="language-bash">scp -r /opt/module/hadoopha/etc/hadoop root@hadoop103:/opt/module/hadoopha/etc</span><br></code></pre></td></tr></table></figure>

<h2 id="4-2-启动测试"><a href="#4-2-启动测试" class="headerlink" title="4.2  启动测试"></a>4.2  启动测试</h2><p>首先启动zk集群</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs shell">[root@hadoop101 ~]# zkServer.sh start<br>[root@hadoop102 ~]# zkServer.sh start<br>[root@hadoop103 ~]# zkServer.sh start<br></code></pre></td></tr></table></figure>
<p>接着启动dfs和yarn</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs shell">[root@hadoop101 ~]# start-dfs.sh<br>[root@hadoop101 ~]# start-yarn.sh<br></code></pre></td></tr></table></figure>

<p>查看集群节点状态：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs shell"><span class="hljs-meta prompt_">$ </span><span class="language-bash"><span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> hadoop101 hadoop102 hadoop103;</span><br>do echo ====节点$i====;<br>ssh $i jps;<br>done<br></code></pre></td></tr></table></figure>
<p>运行结果：<br><img src="https://img-blog.csdnimg.cn/5d29f3e8aae344a9b4fe60e43d901ab9.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"><br>接下来可查询集群节点的状态：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs shell">[root@hadoop101 ~]# yarn rmadmin -getServiceState rm1<br>[root@hadoop101 ~]# yarn rmadmin -getServiceState rm2<br>[root@hadoop101 ~]# yarn rmadmin -getServiceState rm3<br></code></pre></td></tr></table></figure>

<p>运行结果：<br>![在这里插入图片描述](<a target="_blank" rel="noopener" href="https://img-blog.csdnimg.cn/d202be1d201f4f11b7f8de8846043e7f.png#">https://img-blog.csdnimg.cn/d202be1d201f4f11b7f8de8846043e7f.png#</a> &#x3D;50%x)<br>此时通过之前那配置的8088端口号访问RM的web页面（将自动跳转到active状态的RM节点的web页面）</p>
<h2 id="4-3-模拟故障"><a href="#4-3-模拟故障" class="headerlink" title="4.3 模拟故障"></a>4.3 模拟故障</h2><p>kill之前查询到的active RM ，观察结果：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs shell">[root@hadoop103 ~]# jps | grep ResourceManager | awk &#x27;&#123;print $1&#125;&#x27; | xargs kill -9<br></code></pre></td></tr></table></figure>

<p>再次查询yarn RM状态：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs shell">[root@hadoop101 ~]# yarn rmadmin -getServiceState rm1<br>[root@hadoop101 ~]# yarn rmadmin -getServiceState rm2<br>[root@hadoop101 ~]# yarn rmadmin -getServiceState rm3<br></code></pre></td></tr></table></figure>
<p>运行结果：</p>
<p>![在这里插入图片描述](<a target="_blank" rel="noopener" href="https://img-blog.csdnimg.cn/68c2a66327c24fe29899a797a34ee380.png#">https://img-blog.csdnimg.cn/68c2a66327c24fe29899a797a34ee380.png#</a> &#x3D;50%x)<br>此时可以看到rm2转换成了active状态。至此，Hadoop-HA测试完毕。</p>
<h1 id="参-考-资-料"><a href="#参-考-资-料" class="headerlink" title="参  考  资  料"></a>参  考  资  料</h1><hr>
<p>[1] <a target="_blank" rel="noopener" href="https://hadoop.apache.org/docs/stable/hadoop-project-dist/hadoop-hdfs/HDFSHighAvailabilityWithNFS.html">Hadoop-NameNode-HA 官方帮助文档</a><br>[2] <a target="_blank" rel="noopener" href="https://hadoop.apache.org/docs/stable/hadoop-yarn/hadoop-yarn-site/ResourceManagerHA.html">Yarn-ResourceManager-HA 官方帮助文档</a><br>[3] <a target="_blank" rel="noopener" href="https://www.bilibili.com/video/BV1EP4y1j7V1?p=1">Hadoop-HA 视频资料</a></p>

                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/categories/%E5%A4%A7%E6%95%B0%E6%8D%AE/" class="category-chain-item">大数据</a>
  
  

      </span>
    
  
</span>

    </div>
  
  
    <div class="post-meta">
      <i class="iconfont icon-tags"></i>
      
        <a href="/tags/Hadoop/">#Hadoop</a>
      
    </div>
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>Hadoop HA高可用 学习笔记（一） HDFS-HA 手动、自动模式 _ YARN-HA 自动模式 _ 模拟宕机故障 _ HA-基于Zookeeper</div>
      <div>http://example.com/2022/04/06/Hadoop HA高可用 学习笔记（一） HDFS-HA 手动、自动模式 _ YARN-HA 自动模式 _ 模拟宕机故障 _ HA-基于Zookeeper/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>John Doe</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2022年4月6日</div>
        </div>
      
      
      <div class="license-meta-item">
        <div>许可协议</div>
        <div>
          
            
            
              <a target="_blank" href="https://creativecommons.org/licenses/by/4.0/">
              <span class="hint--top hint--rounded" aria-label="BY - 署名">
                <i class="iconfont icon-by"></i>
              </span>
              </a>
            
          
        </div>
      </div>
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2022/04/08/Docker%20%E7%AC%94%E8%AE%B03%20Dockerfile%E6%96%87%E4%BB%B6%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4%20_%20Docker%E7%9A%84%E7%BD%91%E7%BB%9C%E6%9C%BA%E5%88%B6%E4%BA%94%E5%A4%A7%E7%BD%91%E7%BB%9C%E6%A8%A1%E5%BC%8F%EF%BC%8Cbridge%E6%A8%A1%E5%BC%8F%E3%80%81host%E6%A8%A1%E5%BC%8F%E3%80%81none%E6%A8%A1%E5%BC%8F%E3%80%81container%E6%A8%A1%E5%BC%8F%E3%80%81%E8%87%AA%E5%AE%9A%E4%B9%89%E6%A8%A1%E5%BC%8F%E7%9A%84%E6%A6%82%E5%BF%B5%E4%B8%8E%E5%8C%BA%E5%88%AB/" title="Docker 笔记3 Dockerfile文件常用命令 _ Docker的网络机制五大网络模式，bridge模式、host模式、none模式、container模式、自定义模式的概念与区别">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">Docker 笔记3 Dockerfile文件常用命令 _ Docker的网络机制五大网络模式，bridge模式、host模式、none模式、container模式、自定义模式的概念与区别</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2022/04/05/Docker%20%E7%AC%94%E8%AE%B02%20MySQL%E4%B8%AD%E7%BB%A7%E6%97%A5%E5%BF%97%E3%80%81%E8%AF%BB%E5%86%99%E5%88%86%E7%A6%BB%E3%80%81%E4%B8%BB%E4%BB%8E%E6%9E%B6%E6%9E%84%E6%A6%82%E5%BF%B5%20_%20%E4%BD%BF%E7%94%A8Docker%E5%88%9B%E5%BB%BA%E3%80%81%E9%85%8D%E7%BD%AE%E4%B8%8E%E4%BD%BF%E7%94%A8%E4%B8%A4%E4%B8%AAMySQL%E4%B8%BB%E4%BB%8E%E5%BA%93%E5%AE%B9%E5%99%A8/" title="Docker 笔记2 MySQL中继日志、读写分离、主从架构概念 _ 使用Docker创建、配置与使用两个MySQL主从库容器">
                        <span class="hidden-mobile">Docker 笔记2 MySQL中继日志、读写分离、主从架构概念 _ 使用Docker创建、配置与使用两个MySQL主从库容器</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="margin-left: -1rem">
    <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
    </div>
  
  
  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.0/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  
    <script  src="/js/img-lazyload.js" ></script>
  




  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.18.2/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      headingSelector : CONFIG.toc.headingSelector || 'h1,h2,h3,h4,h5,h6',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      collapseDepth   : CONFIG.toc.collapseDepth || 0,
      scrollSmooth    : true,
      headingsOffset  : -boardTop
    });
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.10/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/js/local-search.js" ></script>





<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
</body>
</html>
